package com.otdemo.service;

import com.otdemo.dao.RestScoreDao;
import com.otdemo.entity.RestScore;
import com.otdemo.resp.ResultResponse;
import java.util.List;

public class RestScoreService {

    /**
     * 新增
     *
     * @return
     */
    public ResultResponse insert(RestScore rest) {
        ResultResponse resultResponse = new ResultResponse();
        try {
            new RestScoreDao().insert(rest);
        } catch (Exception e) {
            return resultResponse.fail(e.getMessage());
        }
        return resultResponse.success();
    }

    /**
     * 更新
     *
     * @return
     */
    public ResultResponse update(RestScore rest) {
        ResultResponse resultResponse = new ResultResponse();
        try {
            new RestScoreDao().update(rest);
        } catch (Exception e) {
            return resultResponse.fail(e.getMessage());
        }
        return resultResponse.success();
    }

//    public ResultResponse delete(Score rest) {
//        ResultResponse resultResponse = new ResultResponse();
//        if ("2".equals(rest.getStatus())) {
//            Content book = new RestContentDao().findByUid(rest.getBook());
//            book.setAmount(book.getAmount() + 1);
//            new RestContentDao().update(book);
//        }
//        try {
//            new RestScoreDao().delete(rest);
//        } catch (Exception e) {
//            return resultResponse.fail(e.getMessage());
//        }
//        return resultResponse.success();
//    }


    /**
     * 查询
     *
     * @return
     */
    public ResultResponse findByUid(RestScore rest) {
        ResultResponse resultResponse = new ResultResponse();
        try {
            RestScore rest1 = new RestScoreDao().findByUid(rest.getUid());
            return resultResponse.success(rest1);
        } catch (Exception e) {
            return resultResponse.fail(e.getMessage());
        }
    }

    /**
     * 列表
     *
     * @return
     */
    public ResultResponse list(RestScore rest) {
        ResultResponse resultResponse = new ResultResponse();
        try {
            List<RestScore> list = new RestScoreDao().list();
            return resultResponse.success(list);
        } catch (Exception e) {
            return resultResponse.fail(e.getMessage());
        }
    }
}
